//
//  HttpsTools.swift
//  Swift-WB
//
//  Created by lxy on 2017/6/7.
//  Copyright © 2017年 lixiya. All rights reserved.
//

import Foundation
import Alamofire

typealias Success = (([String: Any]) -> ())
typealias Failure = ((Error) -> ())

class HttpsTools {
    
    static let shared: HttpsTools = HttpsTools()
    
    private init () {}
    
    func get(url: String, parameters: Parameters? = nil, success: @escaping Success, failure: @escaping Failure) {
        Alamofire.request(url, method: .get, parameters: parameters).responseJSON { (response) in
            
            switch response.result {
            case .success(let value):
                print("请求成功 = \(value)")
                success(value as! [String :Any])
            case .failure(let error):
                failure(error)
            }
        }

    }
    
    
    func post(url: String, parameters: Parameters? = nil, success: @escaping Success, failure: @escaping Failure) {
        Alamofire.request(url, method: .post, parameters: parameters).responseJSON { (response) in
            
            switch response.result {
            case .success(let value):
                success(value as! [String :Any])
            case .failure(let error):
                failure(error)
            }

        }
    }
    
    
}
